package com.letv.core.parser;

import org.json.JSONObject;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.letv.core.bean.TabTextLinkBean;
import com.letv.core.bean.TabVideoListBean;
import com.letv.core.bean.VideoListBean;

public class VideoListParser extends LetvMobileParser<VideoListBean>{
    private static final String VIDEOLIST = "videoList";
    private static final String STYLE = "style";
    private static final String TEXTLINK = "textLink";
    
    public String mStyle = "";    
    public TabTextLinkBean mTabTextLinkBean; 
    
	@Override
	public VideoListBean parse(JSONObject data) throws Exception {		
		if(data != null){
		    VideoListBean videoListBean = new VideoListBean();
		    String textLink = getString(data, TEXTLINK);
		    mStyle = getString(data, STYLE); 
	        String videoList = getString(data, VIDEOLIST);
	        
	        if (!TextUtils.isEmpty(textLink)){
	            mTabTextLinkBean = new TabTextLinkBean();
	            mTabTextLinkBean = JSON.parseObject(textLink, TabTextLinkBean.class);
	        }
	        
	        if (!TextUtils.isEmpty(videoList)) {
    	        TabVideoListBean tabVideoListBean = JSON.parseObject(videoList, TabVideoListBean.class);
    	        
    	        videoListBean.addAll(tabVideoListBean.getVideoInfoList());
    	        if (TextUtils.isDigitsOnly(tabVideoListBean.getPagenum())) {
    	            videoListBean.setPagenum(Integer.valueOf(tabVideoListBean.getPagenum()));
    	        }
    	        if (TextUtils.isDigitsOnly(tabVideoListBean.getTotalNum())) {   
    	            videoListBean.setTotalNum(Integer.valueOf(tabVideoListBean.getTotalNum()));
    	        }
    	        if (TextUtils.isDigitsOnly(tabVideoListBean.getEpisodeNum())) {
    	            videoListBean.setEpisodeNum(Integer.valueOf(tabVideoListBean.getEpisodeNum()));
    	        }
    	        if (TextUtils.isDigitsOnly(tabVideoListBean.getShowOuterVideolist())) {
    	            videoListBean.setShowOuterVideolist(Integer.valueOf(tabVideoListBean.getShowOuterVideolist()));
    	        }
    	        if (TextUtils.isDigitsOnly(tabVideoListBean.getVarietyShow())) {
    	            videoListBean.setVarietyShow(Integer.valueOf(tabVideoListBean.getVarietyShow()));
    	        }
	        }
	        return videoListBean;
		}
		
		return null;
	}

    public String getStyle() {
        return mStyle;
    }

    public void setStyle(String style) {
        this.mStyle = style;
    }

    public TabTextLinkBean getTabTextLinkBean() {
        return mTabTextLinkBean;
    }

    public void setTabTextLinkBean(TabTextLinkBean tabTextLinkBean) {
        this.mTabTextLinkBean = tabTextLinkBean;
    }
}
